/*
* 添加零件配件
* */

import 'package:center_beijing/common/numLengthInputFormatter.dart';
import 'package:center_beijing/common/styles.dart';
import 'package:center_beijing/widgets/custom_input_widget.dart';
import 'package:center_beijing/widgets/textarea_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:get/get.dart';

class AddEquipmentPart extends StatefulWidget {

  @override
  _AddEquipmentPartState createState() => _AddEquipmentPartState();
}

class _AddEquipmentPartState extends State<AddEquipmentPart> {

  var nameText = TextEditingController();
  var specifications = '';//规格
  var unit = '';//单位
  var number = '';//数量
  var remark = '';
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('添加配件'),
      ),
      body: SafeArea(
        child: GestureDetector(
          onTap: (){
            FocusScope.of(context).requestFocus(FocusNode());
          },
          child: Container(
            padding: EdgeInsets.only(
                bottom: MediaQuery.of(context).padding.bottom + 40),
            child: SingleChildScrollView(
              child:Column(
                children: [
                  Container(
                    margin: EdgeInsets.fromLTRB(0, Styles.spacing8, 0, 0),
                    padding: EdgeInsets.fromLTRB(
                        Styles.spacing8, 0, Styles.spacing8, 0),
                    child: CustomInput(
                      textAlign: TextAlign.left,
                      inputformat: [
                        LengthLimitingTextInputFormatter(10),
                      ],
                      title: '名称',
                      placeHold: '请输入',
                      textInput: this.nameText,
                      clearAll: false,
                      require: true,
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.fromLTRB(0, Styles.spacing8, 0, 0),
                    padding: EdgeInsets.fromLTRB(
                        Styles.spacing8, 0, Styles.spacing8, 0),
                    child: CustomInput(
                      textAlign: TextAlign.left,
                      inputformat: [
                        LengthLimitingTextInputFormatter(10),
                      ],
                      title: '规格',
                      placeHold: '请输入',
                      clearAll: false,
                      require: false,
                      textChange: (value){
                        specifications = value;
                      },
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.fromLTRB(0, Styles.spacing8, 0, 0),
                    padding: EdgeInsets.fromLTRB(
                        Styles.spacing8, 0, Styles.spacing8, 0),
                    child: CustomInput(
                      textAlign: TextAlign.left,
                      inputformat: [
                        LengthLimitingTextInputFormatter(10),
                      ],
                      title: '单位',
                      placeHold: '请输入',
                      clearAll: false,
                      require: false,
                      textChange: (value){
                        unit = value;
                      },
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.fromLTRB(0, Styles.spacing8, 0, 0),
                    padding: EdgeInsets.fromLTRB(
                        Styles.spacing8, 0, Styles.spacing8, 0),
                    child: CustomInput(
                      textAlign: TextAlign.left,
                      keyboardType:TextInputType.number,
                      inputformat: [
                        LengthLimitingTextInputFormatter(10),
                        NumLengthInputFormatter(digit: 2),
                      ],
                      title: '数量',
                      placeHold: '请输入',
                      clearAll: false,
                      require: false,
                      textChange: (value){
                        number = value;
                      },
                    ),
                  ),
                  Container(
                    color: Colors.white,
                    margin: EdgeInsets.fromLTRB(0, Styles.spacing8, 0, 0),
                    padding: EdgeInsets.fromLTRB(
                        Styles.spacing8, 0, Styles.spacing8, 0),
                    child: TextAreaWidget(
                      maxLength: 100,
                      labelText: '备注',
                      defaultValue: '',
                      placeholder: '请输入',
                      disabled: false,
                      required: false,
                      rows: 4,
                      onChange: (value) => this.setState(() {
                        remark = value;
                      }),
                    ),
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
        floatingActionButtonLocation: FloatingActionButtonLocation.centerDocked,
        floatingActionButton: Container(
          padding: EdgeInsets.fromLTRB(
              Styles.spacing8, Styles.spacing8, Styles.spacing8, 10),
          child: Container(
            decoration: new BoxDecoration(
              //背景
              color: Styles.BlueColor,
              //设置四周圆角 角度
              borderRadius: BorderRadius.all(Radius.circular(12.0)),
            ),
            child: FlatButton(
              disabledColor: Styles.SelectColor,
              onPressed: () {
                if(nameText.text==''){
                  Fluttertoast.showToast(msg: '请输入零件名称');
                }else{
                  Get.back(result: {
                    'partName':nameText.text,
                    'partType':specifications,
                    'partUnit':unit,
                    'partNum':number,
                    'remark':remark
                  });
                }
              },
              child: Container(
                height: Styles.MainButtonHeight,
                alignment: Alignment.center,
                child: Text(
                  '添加',
                  style: TextStyle(
                      fontSize: Styles.MainButtonTextFont, color: Colors.white),
                ),
              ),
            ),
          ),
        )
    );
  }
}
